<%-- 
    Document   : question_bank
    Created on : 2020-5-3, 10:28:03
    Author     : liqianru
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>题目管理</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--图标样式-->
        <link rel="stylesheet" href="css/bootstrap.min.css"/>
        <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <!--主要样式-->
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" href="css/mycss_foradim.css"/>
        <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/circle.js" charset="UTF-8"></script>
    </head>
    <body onload="goPage(1, 10)">
        <script>
            $(function () {
                setInterval(function () {

                    $.ajax({
                        url: 'admin_modifyStatus',
                        type: 'post',
                        async: false,
                        data: {admin_action: "search_status"},
                        success: function (data) {//status 表示申请状态：：0表示未申请
                            if (data < 1) {

                                $(".redpoint").css("display", "inline-block");
                                $("#status_li").css("display", "block");

                            }
                            if (data > 0) {
                                $(".redpoint").css("display", "none");
                                $("#status_li").css("display", "none");
                            }

                        },
                        error: function () {
                            // clearInterval();
                            //  alert("error");
                        }

                    });
                }, 500);
            });

        </script>
        <div id="navdiv">
            <div class="top_navdiv">
                <div class="top_left">管理员中心</div>
                <div class="identity">
                    <span class="message">您好</span><span class="redpoint">1</span>
                    <div class="user_li">
                        <canvas id="myCanvas" width="100" height="30">
                        </canvas>
                    </div>
                    <div class="nd_menu">
                        <ol>
                            <li>回到首页</li>
                            <li><a href="#" onclick="all_logout()">退出登录</a></li>
                            <li id="status_li"><a onclick="refresh()" href="#" data-target="#myModal_status" data-toggle="modal">申请信息</a><span class="redpoint" id="status_span">1</span></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <div class="control_nav ">
            <div class="container">
                <ul class="nav navbar-nav navul">

                    <li class="col-md-2 nav_li">
                        <a href="#"><img class="nav_img" src="img/nav6.png"/> 教师</a>
                        <div class="nav_underline"></div>
                    </li>
                    <li class="col-md-2 nav_li">
                        <a href="#"><img class="nav_img" src="img/nav1.png"/> 班级</a>
                        <div class="nav_underline"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallStu?action=getall"><img class="nav_img" src="img/nav5.png"/> 学生</a>
                        <div class="nav_underline"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallCourse?action1=getall"><img class="nav_img" src="img/nav3.png"/> 课程</a>
                        <div class="nav_underline"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallschedule"><img class="nav_img" src="img/nav2.png"/> 带课</a>
                        <div class="nav_underline"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getTest?action=get"><img class="nav_img" src="img/nav4.png"/> 题目</a>
                        <div class="nav_underline" style="display: block"></div>
                    </li>
                </ul>
            </div>
        </div>
        <div class="container">
            <div class="col-md-3">
                <div class="question_bank main_div nav_list">

                    <span><b>管理员</b></span>
                    <div class="div_line"></div>
                    <ul>
                        <li>
                            <img class="img-circle" width="74px" height="70px;" src="img/login_img.jpg" alt="管理员">
                        </li>
                        <li>
                            <span class="signature" id="admin-signature">Hi,又是充满活力的一天</span><a title="点击更换个性签名" href="javascript:changeAdminSignature(Math.floor(Math.random()*5));"><img src="img/admin_about.png" alt="关于" width="15px" height="15px"></a>
                        </li>
                        <li>
                            <a href="admin_getGrade?action=getall"><img src="img/admin_user.png" alt="user" title="查看成绩" width="20px" height="20px"></a>
                            <a href="index.html"><img src="img/admin_home.png" alt="回到首页" title="回到首页" width="20px" height="20px"></a>
                            <a href="getTest?action=get"><img src="img/admin_case.png" alt="题库管理" title="题库管理" width="20px" height="20px"></a>
                            <a href="getallStu?action=getall"><img src="img/admin_customer1.png" alt="管理学生" title="管理学生" width="20px" height="20px"></a>
                        </li>
                        <li>
                            <a href="#" id="nd-title">思修</a><span class="glyphicon glyphicon-chevron-right"></span>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="col-md-9 main_div">
                <form>
                    <input type="text" class="input-lg" name="keyword" placeholder="输入关键字查询" id="keyword_input">
                    <input type="text" name="action" value="search_Test" hidden>
                    <button  class="btn btn-lg btn-toolbar search_btn" formaction="getTest" formmethod="GET"  >
                        <span class="glyphicon glyphicon-search"></span>
                    </button>
                    <button class="btn btn-sm add_text_btn" type="button" data-target="#myModal" data-toggle="modal">
                        <span class="glyphcion glyphicon-plus">添加题目</span>
                    </button>
                    <button class="btn btn-sm re_text_btn" formaction="getTest" formmethod="GET">
                        <span class="glyphicon glyphicon-repeat">刷新题目</span>
                    </button>
                </form>
                <!---添加题目弹窗-->
                <!-- Modal -->
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-edit title-icon"></i> 添加题目</h4>
                            </div>
                            <div class="modal-body">
                                <form id="add_form">
                                    <div class="test-detail">
                                        <h2>题目描述</h2>
                                        <label for="topic" class="add-lable">请输入题目：</label>
                                        <%---<input type="text" id="topic" class="form-control add-input-title" name="topic">----%>
                                        <textarea type="text" id="topic" class="form-control add-input-title" name="topic"></textarea>
                                        <label for="questionA" class="add-lable">请输入选项A：</label>

                                        <textarea type="text" id="questionA" class="form-control add-input" name="A"></textarea>
                                        <label for="questionB" class="add-lable">请输入选项B：</label>
                                        <textarea type="text" id="questionB" class="form-control add-input" name="B"></textarea>
                                        <label for="questionC" class="add-lable">请输入选项C：</label>
                                        <textarea type="text" id="questionC" class="form-control add-input" name="C"></textarea>
                                        <label for="questionD" class="add-lable">请输入选项D：</label>
                                        <textarea type="text" id="questionD" class="form-control add-input" name="D"></textarea>
                                    </div>
                                    <div class="test-detail">
                                        <div id="answer" class="radio-test-div">
                                            <label for="answer" class="add-lable">请输入试题答案：</label>
                                            <input type="radio" class="radio-test" name="answer" value="A" > <span>A</span>
                                            <input type="radio" class="radio-test" name="answer" value="B" > <span>B</span>
                                            <input type="radio" class="radio-test" name="answer" value="C" > <span>C</span>
                                            <input type="radio" class="radio-test" name="answer" value="D" > <span>D</span>
                                        </div>
                                        <label for="score" class="add-lable">请输入分值：</label>
                                        <input type="text" id="score" class="form-control add-input " name="score"  value="2" readonly>  
                                        <label for="cid" class="add-lable">请输入试题所属课程：<span class="glyphicon glyphicon-remove glyphicon text-danger glyphicon-remove span-iscourse">课程不存在</span></label>
                                        <input type="text" id="cid" class="form-control add-input" name="cid" onblur="coursenameOnblur()">
                                        <label for="courseid" class="add-lable">请输入所属课程编号：</label>
                                        <select name="courseid" id="courseid" class="form-control input-courseid add-input">
                                        </select>
                                        <label for="qid" class="add-lable">请输入试题编号：</label>
                                        <input type='number' id="qid" class="form-control input-qid add-input" name="qid" placeholder="请输入整数">
                                        <input type="text" style="display:none" name="action" value="add">
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary" id="submit_btn" onclick="submit()">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!---编辑题目弹窗-->
                <div class="modal fade" id="myModal_modify_test" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-pencil"></span>修改题目</h4>
                            </div>
                            <div class="modal-body">
                                <div class="tag-modal-img">
                                    <c:forEach begin="1" end="15">
                                        <img src="img/tag-admin.png" alt="wu">
                                    </c:forEach>

                                </div>
                                <form id="modify_form" class="test-detail">
                                    <br>
                                    <label for="topic" class="add-lable">请输入题目：</label>
                                    <input type="text" id="topic" class="form-control input-lg add-input" name="topic">
                                    <label for="questionA" class="add-lable">请输入选项A：</label>
                                    <input type="text" id="questionA" class="form-control add-input" name="A">
                                    <label for="questionB" class="add-lable">请输入选项B：</label>
                                    <input type="text" id="questionB" class="form-control add-input" name="B">
                                    <label for="questionC" class="add-lable">请输入选项C：</label>
                                    <input type="text" id="questionC" class="form-control add-input" name="C">
                                    <label for="questionD" class="add-lable">请输入选项D：</label>
                                    <input type="text" id="questionD" class="form-control add-input" name="D">
                                    <section>
                                        <label for="answer" class="add-lable">请输入试题答案：</label>
                                        <input type="text" id="answer" class="form-control add-input" name="answer">  
                                        <label for="score" class="add-lable">分值：</label>
                                        <input type="text" id="score" class="form-control add-input" name="score" readonly>  
                                        <label for="cid" class="add-lable">试题所属课程：</label>
                                        <input type="text" id="cid" class="form-control add-input" name="cid" readonly>
                                        <label for="qid" class="add-lable">试题编号：</label>
                                        <input type="text" id="qid" class="form-control add-input" name="qid" placeholder="请输入整数" readonly>
                                        <input type="text" style="display:none" name="courseid" value="1001">
                                        <input type="text" style="display:none" name="action" value="modify"><br>
                                        </form>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-primary" id="submit_btn" onclick="modify()">提交</button>
                                        </div>
                                        </div>
                                        </div>
                                        </div>
                                        <!--编辑确认窗口-->
                                        <div class="modal fade" id="myModal_status" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                        <h4 class="modal-title" id="myModalLabel">确认</h4>
                                                    </div>
                                                    <div class="modal-body">
                                                        <p>确认批准考试编号为:<b>${sessionScope.testid}</b>的申请吗？</p>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-primary" id="submit_btn" onclick="modify_status(${sessionScope.testid})">确认</button>
                                                        <button type="button" class="btn btn-default" id="submit_btn" data-dismiss="modal">取消</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <!--实现分页：方法一：利用sql语句-->
                                        <aside class="question_aside">
                                            <a href="javascript:checkAll();" class="btn btn-primary"><span>全选</span></a>
                                            <a href="javascript:uncheckAll();" class="btn btn-success"><span>取消全选</span></a>
                                            <a href="#" onclick="deleteAllBox()" class="btn btn-danger"><span>批量删除</span></a>
                                        </aside>
                                        <table class="table-condensed table-hover test_table table-striped" id="Stu_table">
                                            <tr class="table-hover">
                                                <td class="col-md-1">选择</td>
                                                <td class="col-md-2">题目描述</td>
                                                <td class="col-md-2">选项A</td>
                                                <td class="col-md-2">选项B</td>
                                                <td class="col-md-2">选项C</td>
                                                <td class="col-md-1">选项D</td>
                                                <td class="col-md-2">操作</td>

                                            </tr>

                                            <c:forEach items="${sessionScope.allTest}" var="i">
                                                <tr class="forEach_tr" id="tr${i.qid}">
                                                    <td class="col-md-1"><input type="checkbox" name="checkbox" value="${i.qid}"></td>
                                                    <td class="col-md-3" id="topic${i.qid}">${i.topic}</td>
                                                    <td class="col-md-2" id="a${i.qid}">${i.qestionA}</td>
                                                    <td class="col-md-2" id="b${i.qid}">${i.qestionB}</td>
                                                    <td class="col-md-2" id="c${i.qid}">${i.qestionC}</td>
                                                    <td class="col-md-1" id="d${i.qid}">${i.qestionD}</td>
                                                    <td id='answer${i.qid}' style="display:none">${i.answer}</td>
                                                    <td id='score${i.qid}' style="display:none">${i.score}</td>
                                                    <td id='cid${i.qid}' style="display:none">${i.coursename}</td>
                                                    <td id='qid${i.qid}' style="display:none">${i.qid}</td>
                                                    <td class="col-md-1" id="oper${i.qid}"><a href="#" onclick="show_detail(${i.qid})" class="delete_a text-success" data-target="#myModal_modify_test" data-toggle="modal">编辑</a> <a href="#"  onclick="deleteTest('${i.qid}')" class="delete_a text-danger">删除</a></td>
                                                </tr>
                                            </c:forEach>
                                        </table>

                                        <div id="barcon" name="barcon" class="index_div"></div>

                                        </div>
                                        </div>
                                        <script>
                                            function refresh() {
                                                $("#myModal_status p").load(location.href + "#myModal_status p");
                                            }
                                            $(".grade_tip").hover(function () {
                                                $(".float_div").fadeIn(100);
                                            }, function () {
                                                $(".float_div").fadeOut(100);
                                            });
                                        </script>

                                        <script>
                                            function submit() {
                                                $.ajax({
                                                    url: "add",
                                                    type: "POST",
                                                    data: $("#add_form").serialize(),
                                                    success: function () {
                                                        alert("success");
                                                        $('#myModal').modal('hide');
                                                        window.location.reload();
                                                    }
                                                });
                                            }
                                            function show_detail(qid) {
                                                $("#modify_form #topic").val($("#topic" + qid).text());
                                                $("#modify_form #questionA").val($("#a" + qid).text());
                                                $("#modify_form #questionB").val($("#b" + qid).text());
                                                $("#modify_form #questionC").val($("#c" + qid).text());
                                                $("#modify_form #questionD").val($("#d" + qid).text());
                                                $("#modify_form #answer").val($("#answer" + qid).text());
                                                $("#modify_form #cid").val($("#cid" + qid).text());
                                                $("#modify_form #qid").val($("#qid" + qid).text());
                                                $("#modify_form #score").val($("#score" + qid).text());
                                            }
                                            function modify() {
                                                $.ajax({
                                                    url: "add",
                                                    type: "POST",
                                                    data: $("#modify_form").serialize(),
                                                    success: function (data) {
                                                        if (data < 1) {
                                                            alert("修改失败，请检查输入格式");
                                                            return;
                                                        } else {
                                                            alert("success");
                                                            $('#myModal_modify').modal('hide');
                                                            window.location.reload();
                                                        }
                                                    },
                                                    error: function () {
                                                        alert("error");
                                                    }
                                                });
                                            }
                                            function modify_status(testid) {
                                                $.ajax({
                                                    url: 'admin_modifyStatus',
                                                    type: 'post',
                                                    async: false,
                                                    data: {admin_action: "modify_status"},
                                                    success: function (data) {//status 表示申请状态：：0表示未申请
                                                        $("#myModal_status").modal('hide');

                                                    },
                                                    error: function () {
                                                        alert("error");
                                                    }

                                                });
                                            }

                                        </script>

                                        </body>
                                        </html>
